package com.sheep.springboot.service.impl;

import com.sheep.springboot.bean.ProvinceVo;
import com.sheep.springboot.service.ProMapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * author: sheep.Old
 * qq: 64341393
 * Created 2018/11/1
 */
@Service
public class ProMapServiceImpl implements ProMapService {

    @Autowired
    public RedisTemplate<String, String> redisTemplate;

    @Override
    public List<ProvinceVo> findAllMapdata(String key) {
        System.out.println("key = " + key);
        Map<Object, Object> entries = redisTemplate.opsForHash().entries(key);

        List<ProvinceVo> list = new ArrayList<>();
        if (entries != null) {
            for (Map.Entry<Object, Object> entry : entries.entrySet()) {
                ProvinceVo vo = new ProvinceVo(entry.getKey().toString(), Integer.parseInt(entry.getValue().toString()));
                list.add(vo);
            }
        }
        return list;
    }
}
